#include "CameraListener.h"

CCameraListener::CCameraListener(Ogre::SceneNode * pCameraNode_)
{
	m_pCameraNode=pCameraNode_;
	m_fForward_Speed=0.0f;
}

CCameraListener::~CCameraListener(void)
{
}

bool 
CCameraListener::frameStarted(const Ogre::FrameEvent& evt)
{
	m_pCameraNode-> translate(0,0,m_fForward_Speed*evt.timeSinceLastFrame,Ogre::SceneNode::TS_LOCAL);
	return true;
}

bool 
CCameraListener::mouseMoved( const OIS::MouseEvent &arg )
{
	//MOUSE ROTATION SPEED
float mRotate=0.25f;

m_pCameraNode->yaw(Ogre::Degree(-mRotate * arg.state.X.rel), Ogre::Node::TS_WORLD);

m_pCameraNode->pitch(Ogre::Degree(-mRotate * arg.state.Y.rel), Ogre::Node::TS_LOCAL);

	return true;
}


bool 
CCameraListener::mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id )
{
	return true;
}


bool 
CCameraListener::mouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id )
{
	return true;
}

bool 
CCameraListener::keyPressed(const OIS::KeyEvent &arg)
{
	//ASSIGN BUTTONS + CAMERA SPEED
	if (arg.key==OIS::KC_PGUP)
	{
		m_fForward_Speed=-10.0f;
	}
	if (arg.key==OIS::KC_PGDOWN)
	{
		m_fForward_Speed=10.0f;
	}
return true;
}



bool 
CCameraListener::keyReleased(const OIS::KeyEvent &arg)
{
	//SETS CAMERA SPEED TO 0 WHEN THE KEY IS RELEASED
	if (arg.key==OIS::KC_PGUP || arg.key==OIS::KC_PGDOWN)
	{
		m_fForward_Speed=0.0f;
	}

	return true;
}